﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.SharePoint;
using Microsoft.SharePoint.PowerShell;

using Microsoft.Office.Server.Search.Administration;
using Microsoft.Office.Server.Search.Cmdlet;

namespace Community.SharePoint.PowerShell
{
    /// <summary>
    /// SharePoint PowerShell Community Kit
    /// This cmdlet takes a SPSearchServiceApplication from a pipe bind and starts
    /// Enterprise Search scope compilation.
    /// Example (Starts scope compilation):
    /// Get-SPEnterpriseSearchServiceApplication "Search Service Application" | Start-SPEnterpriseSearchQueryScopesCompilation
    /// Author: Corey Roth (coreyroth@gmail.com)
    /// Creation Date: 8/9/2010
    /// http://www.dotnetmafia.com
    /// </summary>
    [Cmdlet("Start", "SPEnterpriseSearchQueryScopesCompilation")]
    [SPCmdlet(RequireLocalFarmExist=true)]
    public class StartSearchQueryScopeCompilation : SPCmdlet
    {
        [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0)]
        public SearchServiceApplicationPipeBind Identity { get; set; }

        protected override void InternalProcessRecord()
        {
            SearchServiceApplication searchServiceApplication = Identity.Read();
            searchServiceApplication.StartScopesCompilation();
        }
    }
}
